package algorithm.aStart_8number;

import java.util.ArrayList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.TreeSet;

import library.Tracer;

import org.junit.Test;

public class AStartTest {
	@Test
	public void test1() {
		// Tracer.addTestingTitle("scaffolding1");

		Tracer.addTestingCatalog("size");

		String[] strings = new String[] { "1", "2", "3", "4", "5", "6", "7", "8", "#" };
		Node node = new Node(0, 3, strings);
		Tracer.splitLine("initial");
		node.disp();
		Tracer.splitLine("solve");

		AStart aStart = new AStart();
		node = aStart.find(node);
		node.disp();
	}

	public void test5() {
		/*
		 * if queue can store same elements? if queue can poll element
		 * correctly? the relationship between equals and compareTo
		 */

		Queue<Node> queue = new PriorityQueue<Node>(1000, new Node(""));
		String[] strings = new String[] { "1", "2", "3", "4", "5", "6", "7", "8", "#" };
		Node node = new Node(0, 3, strings);
		Node tmp;

		node.name = "root";
		queue.add(node);
		queue.add(tmp = new Node(node));
		tmp.name = "first";
		node.swapTo(0);
		queue.add(tmp = new Node(node));
		tmp.name = "second";
		node.swapTo(3);

		// System.out.println(node.equals(new Node(node)));
		// System.out.println(node.isEquals(new Node(node)));
		System.out.println(queue.size());

		while (queue.size() > 0) {
			queue.poll().disp();
		}
	}

	public void test4() {
		ArrayList<Node> list = new ArrayList<Node>();

		String[] strings = new String[] { "1", "2", "3", "4", "5", "6", "7", "8", "#" };

		Node node = new Node(0, 3, strings);

		list.add(node);
		node.disp();
		Node node1 = new Node(node);
		// node.swapTo(1);
		System.out.println("========");
		node.disp();
		System.out.print(node.isBoardEquals(node1));
	}

	public void test2() {
		TreeSet<Node> openTab = new TreeSet<Node>();
		String[] strings = new String[] { "1", "2", "3", "4", "5", "6", "7", "8", "#" };
		Node node = new Node(0, 3, strings);
		for (int i = 0; i < 10; i++) {
			if (!openTab.add(node)) {
				System.out.println("fail");
				break;
			}
			node.disp();
		}
		System.out.println("size of openTab is: " + openTab.size());
	}

	// @Test
	public void test3() {
		TreeSet<Node> set = new TreeSet<Node>(new Node(""));

		String[] strings = new String[] { "1", "2", "3", "4", "5", "6", "7", "8", "#" };
		Node node = new Node(0, 3, strings);
		Node tmp;
		boolean suc;

		node.name = "root";
		set.add(node);
		node.disp();

		suc = set.add(tmp = new Node(0, 3, strings));
		tmp.disp();
		System.out.println("add status:" + suc);
		tmp.name = "first";

		suc = set.add(tmp = new Node(0, 3, strings));
		tmp.disp();
		System.out.println("add status:" + suc);
		tmp.name = "second";

		Tracer.splitLine("removing");
		System.out.println(set.size());
		while (set.size() > 0) {
			tmp = set.first();
			set.remove(tmp);
			tmp.disp();
		}
	}

}
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//